﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if DOT_NET
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
#endif
using StyleMVVM.UnitTests.Data.Transform.TestClasses.A;
using StyleMVVM.Data.Activation;
using StyleMVVM.DependencyInjection;
using StyleMVVM.Data.Transform;

namespace StyleMVVM.UnitTests.Data.Transform
{
	[TestClass]
	public class TransformServiceTests : BaseTestClass
	{
		[TestMethod]
		public void TransformClassToExactly()
		{
			ITransformService transformService =
				Container.Locate<ITransformService>();

			TestClassA testClassA = new TestClassA
				                        {
					                        Int1 = 50,
					                        Double1 = 1.5,
					                        String1 = "Hello Sam"
				                        };

			ExactlyLikeA exactlyLikeA =
				transformService.Transform<TestClassA, ExactlyLikeA>(testClassA);

			Assert.IsNotNull(exactlyLikeA);
			Assert.AreEqual(testClassA.Int1, exactlyLikeA.Int1);
			Assert.AreEqual(testClassA.Double1, exactlyLikeA.Double1);
			Assert.AreEqual(testClassA.String1, exactlyLikeA.String1);

			testClassA = transformService.Transform<ExactlyLikeA, TestClassA>(exactlyLikeA);

			Assert.IsNotNull(exactlyLikeA);
			Assert.AreEqual(exactlyLikeA.Int1, testClassA.Int1);
			Assert.AreEqual(exactlyLikeA.Double1, testClassA.Double1);
			Assert.AreEqual(exactlyLikeA.String1, testClassA.String1);
		}

		[TestMethod]
		public void TransformSameAsAButMapped()
		{
			ITransformService transformService =
				Container.Locate<ITransformService>();

			TestClassA testClassA = new TestClassA
				                        {
					                        Int1 = 50,
					                        Double1 = 1.5,
					                        String1 = "Hello Sam"
				                        };

			SameAsAButMapped sameAsA =
				transformService.Transform<TestClassA, SameAsAButMapped>(testClassA);

			Assert.IsNotNull(sameAsA);
			Assert.AreEqual(testClassA.Int1, sameAsA.Int2);
			Assert.AreEqual(testClassA.Double1, sameAsA.Double2);
			Assert.AreEqual(testClassA.String1, sameAsA.String2);

			testClassA = transformService.Transform<SameAsAButMapped, TestClassA>(sameAsA);

			Assert.IsNotNull(testClassA);
			Assert.AreEqual(sameAsA.Int2, testClassA.Int1);
			Assert.AreEqual(sameAsA.Double2, testClassA.Double1);
			Assert.AreEqual(sameAsA.String2, testClassA.String1);
		}

		[TestMethod]
		public void TransformDifferentButSame()
		{
			ITransformService transformService =
				Container.Locate<ITransformService>();

			TestClassA testClassA = new TestClassA
				                        {
					                        Int1 = 50,
					                        Double1 = 1.5,
					                        String1 = "72"
				                        };

			DifferentButSameA kindaA =
				transformService.Transform<TestClassA, DifferentButSameA>(testClassA);

			Assert.IsNotNull(kindaA);
			Assert.AreEqual(50, kindaA.Int1);
			Assert.AreEqual("1.5", kindaA.Double1);
			Assert.AreEqual(72, kindaA.String1);

			testClassA =
				transformService.Transform<DifferentButSameA, TestClassA>(kindaA);

			Assert.IsNotNull(testClassA);
			Assert.AreEqual(50, testClassA.Int1);
			Assert.AreEqual(1.5, testClassA.Double1);
			Assert.AreEqual("72", testClassA.String1);
		}

		[TestMethod]
		public void TransformListTest()
		{
			ITransformService transformService =
				Container.Locate<ITransformService>();

			TestClassA[] aList = new TestClassA[2];

			aList[0] = new TestClassA { Double1 = 1, Int1 = 4, String1 = "1" };
			aList[1] = new TestClassA { Double1 = 2, Int1 = 8, String1 = "5" };

			List<DifferentButSameA> kindaA =
				transformService.Transform<TestClassA[], List<DifferentButSameA>>(aList);

			kindaA.ToString();
		}
	}
}